﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using System.Data;
using System.Data.SqlClient;

namespace DAO
{
    public class ChiTietPhieuThueDAO
    {
        public class SqlConnectionData
        {
            public static SqlConnection Connection()
            {
                SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=QLKSAN;Integrated Security=True");
                return conn;
            }
        }

        public static DataTable GetAll()
        {
            SqlConnection conn = SqlConnectionData.Connection();
            SqlCommand cmd = new SqlCommand("sp_ChiTietPhieuThueGetAll", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(dt);
            return dt;

        }
        public static void InsertChiTieuPhieuThue(ChiTietPhieuThueDTO ctpt)
        {
            SqlConnection conn = SqlConnectionData.Connection();
            SqlCommand cmd = new SqlCommand("sp_InsertChiTietPhieuThue", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@MaPhieuThue", SqlDbType.Int);
            cmd.Parameters.Add("@MaKhachHang", SqlDbType.Int);
            cmd.Parameters["@MaPhieuThue"].Value = ctpt.MaPhieuThue;
            cmd.Parameters["@MaKhachHang"].Value = ctpt.MaKhachHang;
            conn.Open();
            cmd.ExecuteNonQuery();
            conn.Close();
        }

        //************************************************//
        //Author:Nguyen Tan Phat
        //MSSV:1173025
        //Class:11HT
        #region
        public static void Insert(ChiTietPhieuThueDTO chitietphieuthue)
        {
            var pr = new SqlParameter[3];
            pr[0] = new SqlParameter(@"MaChiTietPhieuThue", chitietphieuthue.MaChiTietPhieuThue) { Direction = ParameterDirection.Output };
            pr[1] = new SqlParameter(@"MaPhieuThue", chitietphieuthue.MaPhieuThue);
            pr[2] = new SqlParameter(@"MaKhachHang", chitietphieuthue.MaKhachHang);
            SqlHelper.ExecuteNonQuery(ConnectionString.Text, CommandType.StoredProcedure, "CHITIETPHIEUTHUE_Insert", pr);
        }
        public static void Delete(int MaChiTietPhieuThue)
        {
            var pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"MaChiTietPhieuThue", MaChiTietPhieuThue);
            SqlHelper.ExecuteNonQuery(ConnectionString.Text, CommandType.StoredProcedure, "CHITIETPHIEUTHUE_Delete", pr);
        }
        #endregion
        //************************************************//

    }
}
